package com.shell.customer.group.service.impl;

import com.shell.bee.acct.account.po.AcctBkp;
import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.contract.ContService;
import com.shell.bee.contract.po.ContBas;
import com.shell.customer.chain.callback.CallbackService;
import com.shell.customer.trade.service.CustomerAcctService;
import com.shell.customer.trade.service.TradeService;
import com.shell.framework.utils.SysDateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("groupCancelCallbackService")
public class GroupCancelCallbackServiceImpl implements CallbackService {
	@Autowired
	private CustomerAcctService customerAcctService;
	@Autowired
	private ContService contService;
	@Autowired
	private TradeService tradeService;

	public String getType() {
		return "cc_fin_buy";
	}

	public void confirm(AcctTxRec tran) {
		this.tradeService.callback(tran);

		AcctBkp acctBkp = this.customerAcctService.getAcctBkp(tran.getTxBkpId());
		this.customerAcctService.moveHistory(acctBkp);

		ContBas cont = this.contService.getContBasBySn(acctBkp.getBkpCttNo());
		cont.setContState("0");
		cont.setContInvDate(SysDateUtil.getSystemDate());
		this.contService.updateCont(cont);
	}

	public void cancel(AcctTxRec tran) {
		this.tradeService.rollback(tran);
	}
}
